<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>客户查看</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/xadmin.js"></script>
      <script charset="utf-8" language="javascript" type="text/javascript" src="JS/CommonFields/common.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>
    <div class="x-body">
        <form class="layui-form">
<%--            ID--%>
          <div class="layui-form-item">
              <label for="customerId" class="layui-form-label">
                  <span class="x-red">*</span>客户ID
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="customerId" name="customerId" required="" lay-verify="required"  readonly="readonly"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
<%--    客户姓名--%>
            <div class="layui-form-item">
                <label for="customerName" class="layui-form-label">
                    <span class="x-red">*</span>客户姓名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="customerName" name="customerName" required="" lay-verify="required"  readonly="readonly"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                </div>
            </div>
<%--    客户性别--%>
          <div class="layui-form-item">
              <label  class="layui-form-label">
                  <span class="x-red">*</span>性别
              </label>
              <div class="layui-input-inline">
                  <input type="radio" name="customerGender" value="1" title="男" checked>
                  <input type="radio" name="customerGender" value="2" title="女" >
              </div>
              <div class="layui-form-mid layui-word-aux">
              </div>
          </div>
<%--    客户类别--%>
            <div class="layui-form-item">
                <label  class="layui-form-label">
                    <span class="x-red">*</span>客户类型
                </label>
                <div class="layui-input-inline">
                    <select name="typeId" lay-verify="required">
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                </div>
            </div>
<%--          <div class="layui-form-item">--%>
<%--              <label class="layui-form-label"><span class="x-red">*</span>角色</label>--%>
<%--              <div class="layui-input-block" id="roles-box">--%>
<%--                <input type="checkbox" name="types" lay-skin="primary" title="超级管理员" checked="">--%>
<%--                <input type="checkbox" name="types" lay-skin="primary" title="编辑人员">--%>
<%--                <input type="checkbox" name="types" lay-skin="primary" title="宣传人员" checked="">--%>
<%--              </div>--%>
<%--          </div>--%>
<%--   客户状态 --%>
            <div class="layui-form-item">
                <label  class="layui-form-label">
                    <span class="x-red">*</span>客户状态
                </label>
                <div class="layui-input-inline">
                    <input type="radio" name="customerStatus" value="1" title="正常" checked>
                    <input type="radio" name="customerStatus" value="0" title="流失" >
                </div>
                <div class="layui-form-mid layui-word-aux">
                </div>
            </div>
<%--    消费次数--%>
            <div class="layui-form-item">
                <label for="consumptionTimes" class="layui-form-label">
                    <span class="x-red">*</span>消费次数
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="consumptionTimes" name="consumptionTimes" required="" lay-verify="required"  readonly="readonly"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                </div>
                <hr class="layui-border-black">
            </div>
<%--                质量满意度--%>
                <div class="layui-form-item">
                    <label for="qualitySatisfaction" class="layui-form-label">
                        <span class="x-red">*</span>质量满意度
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="qualitySatisfaction" name="qualitySatisfaction" required="" lay-verify="required"  readonly="readonly"
                               autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                    </div>
<%--                    服务满意度--%>
                    <div class="layui-form-item">
                        <label for="serviceSatisfaction" class="layui-form-label">
                            <span class="x-red">*</span>服务满意度
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="serviceSatisfaction" name="serviceSatisfaction" required="" lay-verify="required"  readonly="readonly"
                                   autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux">
                        </div>
<%--性价比满意度--%>
                        <div class="layui-form-item">
                            <label for="costeffectiveSatisfaction" class="layui-form-label">
                                <span class="x-red">*</span>性价比满意度
                            </label>
                            <div class="layui-input-inline">
                                <input type="text" id="costeffectiveSatisfaction" name="costeffectiveSatisfaction" required="" lay-verify="required"  readonly="readonly"
                                       autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">
                            </div>
<%--总体满意度--%>
                            <div class="layui-form-item">
                                <label for="totalSatisfaction" class="layui-form-label">
                                    <span class="x-red">*</span>总体满意度
                                </label>
                                <div class="layui-input-inline">
                                    <input type="text" id="totalSatisfaction" name="totalSatisfaction" required="" lay-verify="required"  readonly="readonly"
                                           autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">
                                </div>
            </div>
<%--客户反馈--%>
                            <%--客户反馈--%>
                            <div class="layui-form-item">
                                <label for="feedback" class="layui-form-label">
                                    <span class="x-red">*</span>客户反馈
                                </label>
                                <div class="layui-input-inline">
                                    <input type="text" id="feedback" name="feedback" required="" lay-verify="required"
                                           autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">
                                </div>
                            </div>
      </form>
    </div>
    <script>
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
            form = layui.form;
            var layer = layui.layer;

          //监听提交
          form.on('submit(add)', function(data){
            var postData = data.field;
            //发异步，把数据提交给java
            // 提交后台
              $.ajax({
                  type:"post",
                  url:"${pageContext.request.contextPath}/customer/add/do",
                  data: postData,
                  dataType: "json",
                  success:function (res) {
                      console.log(res);
                      layer.alert(res.msg, {icon: 6},function () {
                            // 刷新父级的表格
                            parent.table.reload('data');
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);

                      });
                  }
              });

            return false;
          });


        // 获取 客户类别列表
        $.ajax({
            type:"post",
            url:"${pageContext.request.contextPath}/customer/typelist/data",
            dataType: "json",
            success:function (res) {
                if (res.code === 0){
                    $("select[name=typeId]").empty();
                    $(res.data).each(function () {
                        // 动态创建
                        var option = $('<option value="'+this.typeId+'">'+this.typeName+'</option>')
                        // 追加
                        $("select[name=typeId]").append(option);
                    });
                    // 重新渲染表单
                    form.render('select');
                }
            }
        });


            // 获取员工的详细信息
            var customerId = "${customerId}";
            $.ajax({
                type:"post",
                url:"${pageContext.request.contextPath}/customer/detail",
                data:{id: customerId},
                async: false,
                dataType: "json",
                success:function (res) {
                    console.log(res);
                    if (res.code === 200){
                        // 做数据回显
                        var data = res.data;
                        $("#customerId").val(data.customerId);
                        $("#customerName").val(data.customerName);
                        // 回显性别
                        $("input[name=customerGender]").each(function () {
                            if (data.customerGender == $(this).val()){
                                $(this).prop("checked", true);
                            }
                        })
                        // 回显客户类型
                        $("select[name=typeId]").val(data.typeId);
                        //回显客户状态
                        $("input[name=customerStatus]").each(function () {
                            if (data.customerStatus == $(this).val()){
                                $(this).prop("checked", true);
                            }
                        })
                        // 回显消费次数
                        $("#consumptionTimes").val(data.value.consumptionTimes);
                        //回显质量满意度
                        $("#qualitySatisfaction").val(data.satisfaction.qualitySatisfaction);
                        //回显服务满意度
                        $("#serviceSatisfaction").val(data.satisfaction.serviceSatisfaction);
                        //回显性价比满意度
                        $("#costeffectiveSatisfaction").val(data.satisfaction.costeffectiveSatisfaction);
                        //回显总体满意度
                        $("#totalSatisfaction").val(data.satisfaction.totalSatisfaction);
                        //回显意见
                        $("#feedback").val(data.satisfaction.feedback);

                        form.render();

                    }
                }
            });

        });
    </script>

  </body>

</html>